/*
 Find all prime combinations for a pcular number
 For example:
    12 = 2 * 2 * 3
*/

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int num;
    int fac = 2;
    char s[20];

    if (argc < 2) return -1;

    num = atoi(argv[1]);
    if (num < 2) return -1;
    printf("factors of %d are:\n\t", num);

    while (fac <= (int)sqrt(num)) {
        if (num % fac == 0) {
            snprintf(s, sizeof(s), "%d ", fac);
            printf("%s", s);
            num /= fac;
        } else {
            fac ++;
        }
    }
    snprintf(s, sizeof(s), "%d \n", num);
    printf("%s", s);
    return 0;
}

